package com.kt.uokos.yimo.wx.service.impl;

import com.kt.uokos.yimo.wx.dao.User;
import com.kt.uokos.yimo.wx.example.UserExample;
import com.kt.uokos.yimo.wx.mapper.UserMapper;
import com.kt.uokos.yimo.wx.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * @Description TODO
 * @ClassName UserServiceImpl
 * @Date 2022/1/5 11:53 AM
 * @Author KangTao
 */
@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;

    public User queryByOid(String openId) {
        UserExample example = new UserExample();
        example.or().andWeixinOpenidEqualTo(openId).andDeletedEqualTo(false);
        return userMapper.selectOneByExample(example);
    }

    public void add(User user) {
        user.setAddTime(LocalDateTime.now());
        user.setUpdateTime(LocalDateTime.now());
        userMapper.insertSelective(user);
    }

    public int updateById(User user) {
        user.setUpdateTime(LocalDateTime.now());
        return userMapper.updateByPrimaryKeySelective(user);
    }

    @Override
    public User queryById(Integer id) {
        return userMapper.selectByPrimaryKey(id);
    }
}
